package com.cyf.db.mapper;

import com.cyf.db.bean.UserInvoice;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by asus on 2019/4/13.
 */
@Mapper
public interface UserInvoiceMapper {
    @Insert("insert into user_invoice (invoiceType,invoice,invoiceTaxNumber,userId,plate,createdTime)" +
            " values (#{userInvoice.invoiceType},#{userInvoice.invoice},#{userInvoice.invoiceTaxNumber},#{userInvoice.userId}," +
            "#{userInvoice.plate},now())")
    void insertUserInvoice(@Param("userInvoice") UserInvoice userInvoice);

    /**
     * 根据车牌号检索数量
     *
     * @param plate
     * @return
     */
    @Select("select count(*) from user_invoice where plate=#{plate}")
    int selectUserInvoice(@Param("plate") String plate);


    /**
     * 根据车牌号对象
     *
     * @param plate
     * @return
     */
    @Select("select * from user_invoice where plate=#{plate} limit 0,1")
    UserInvoice selectUserInvoiceByPlate(@Param("plate") String plate);

    @Select(" SELECT * FROM user_invoice WHERE userId = #{userId} ")
    List<UserInvoice> selectUserInvoiceListByUserId(@Param("userId") Integer userId);

    @Delete(" DELETE FROM user_invoice WHERE id = #{id} ")
    void deleteUserInvoiceById(@Param("id") Integer id);

    /**
     * 根据车牌号更新税号
     *
     * @param userInvoice
     */
    @Update("update user_invoice set invoiceType=#{userInvoice.invoiceType}," +
            "invoice=#{userInvoice.invoice},invoiceTaxNumber=#{userInvoice.invoiceTaxNumber} " +
            "WHERE plate=#{userInvoice.plate}")
    void updateUserInvoiceByPlate(@Param("userInvoice") UserInvoice userInvoice);

}
